<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2018/7/2
 * Time: 9:32
 */
namespace app\admin\controller;
use think\Request;
use think\Db;

class Money extends \app\admin\controller\Base
{
    protected $res = array(
        'index'   => array('css' => '2,3,4', 'js' => 'list,My97DatePicker'),
    );

    /**
     * 首页数据
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function index(){
        $pay = input('pay');
        $type = input('type');
        $state = input('state');
        $keywords = input('keywords');
        $pay_start = input('pay_start');
        $pay_end = input('pay_end');
        $map = [];
        if($pay&&$pay!=''){
            $map['o.order_type'] = $pay;
        }
        if($type&&$type!=""){
            $map['o.order_long_type'] = $type;
        }
        if($state&&$state!=""){
            $map['o.order_status'] = $state;
        }
        if($keywords&&$keywords!=""){
            $map['o.order_id|u.user_username'] = ['like',"%" . $keywords . "%"];
        }
        if($pay_start&&$pay_start!==""&&$pay_end=="")
        {
            $map['o.order_ali_paytime'] = ['>= time',$pay_start];
        }
        if($pay_end&&$pay_end!==""&&$pay_start=="")
        {
            $map['o.order_ali_paytime'] = ['<= time',$pay_end];
        }
        if($pay_start&&$pay_start!==""&&$pay_end&&$pay_end!=="")
        {
            $map['o.order_ali_paytime'] = ['between time',[$pay_start,$pay_end]];
        }
        $page = input('param.page');
        $list = Db::table('up_order')
            ->alias('o')
            ->join('up_u_user u','o.order_user_id=u.user_id','left')
            ->join('up_user_auth_long l','o.order_long_id=l.long_id','left')
            ->field('o.order_id,o.order_long_type,o.order_user_pay,o.order_type,o.order_ali_paytime,o.order_status,u.user_username,l.long_how')
            ->where($map)
            ->order('o.order_ali_paytime desc')
            ->paginate(15);
        if(!$page){
            $pages = 0;
        }else{
            $pages = $page-1;
        }
        $action = '/' . Request::instance()->controller() . '/' . Request::instance()->action();
        $this->assign ([
            'page'=>$page,
            'list'=>$list,
            'pages'=>$pages,
            'action'=>$action,
            'pay'=>$pay,
            'type'=>$type,
            'state'=>$state,
            'keywords'=>$keywords,
            'pay_start'=>$pay_start,
            'pay_end'=>$pay_end
        ]);
        return $this->fetch();
    }
}